package pkg

import (
	jwtmiddleware "github.com/auth0/go-jwt-middleware"
	"io"
	"log"
	"net/http"
	"time"
)

package main

import (
"io"
"log"
"net/http"
"time"

 "github.com/auth0/go-jwt-middleware"
"github.com/dgrijalva/jwt-go"
)

const (
	APP_KEY = "www.topgoer.com"
)



// TokenHandler是我们获取用户名和密码的处理程序，如果有效，则返回用于将来请求的令牌。
func TokenHandler(w http.ResponseWriter, r *http.Request) {



	// 颁发一个有限期一小时的证书
	token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
		"user": username,
		"exp":  time.Now().Add(time.Hour * time.Duration(1)).Unix(),
		"iat":  time.Now().Unix(),
	})
	tokenString, err := token.SignedString([]byte(APP_KEY))

	return tokenString, err

}

//AuthMiddleware是我们用来检查令牌是否有效的中间件。如果返回401状态无效，则返回给客户。
